package com.lagou.rabbitmq.rabbit;

import com.lagou.rabbitmq.mapper.OrderMapper;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName RabbitListener
 * @Description
 * @Author playboy
 * @Date 2021/8/29 1:47 下午
 * @Version 1.0
 **/
@Component
public class MyRabbitListener {
	private static Logger log = LoggerFactory.getLogger(MyRabbitListener.class);

	@Autowired
	private OrderMapper orderMapper;


	@RabbitListener(queues = "queue.pay.dlx")
	public void orderTtlMessage(@Payload String id, Channel channel){
		log.info("id:{}的订单收到了检测超时事件");
		Map map = new HashMap();
		map.put("id",Long.parseLong(id));
		map.put("newStatus","02");
		map.put("oldStatus","00");
		int i = orderMapper.updateByIdAndStatus(map);
		if(i>0){
			log.info("id:{}的订单超时了");
		}
	}

}
